#include<linux/module.h>
#include<linux/sched.h>
#include<linux/pid.h>
#include<linux/wait.h>
#include<linux/completion.h>
#include<linux/kthread.h>
MODULE_LICENSE("GPL");

static struct completion comple;
struct task_struct *old_thread;

int my_function(void *argc)
{
	printk("in the kernel thread function.\n");
	printk("the current pid is:%d\n",current->pid);
	printk("the value of done of the comple:%d\n",comple.done);
	printk("the state of the init function is:%ld\n",old_thread->state);

	complete_all(&comple);
	printk("the value of done of the comple:%d\n",comple.done);
	printk("the state of the init function is :%ld\n",old_thread->state);
	printk("out the kernel thread function\n");
	return 0;
}
static int __init complete_all_init(void)
{
	char namefrm[]="complete_all";
	struct task_struct *result;
	long left_time;
	wait_queue_t data;
	printk("into complete_all_init.\n");
	old_thread=current;
	result=kthread_create_on_node(my_function,NULL,-1,namefrm);
	wake_up_process(result);
	init_completion(&comple);
	init_waitqueue_entry(&data,current);
	add_wait_queue(&(comple.wait),&data);
	left_time=schedule_timeout_uninterruptible(1000);
	printk("the return result of the schedule_timeout_uninterruptible is:%ld\n",left_time);
	printk("the pid of result is:%d\n",result->pid);
	printk("the current pid is:%d\n",current->pid);
	printk("out complete_all_init.\n");
	return 0;
}
static void __exit complete_all_exit(void)
{
	printk("Goodbye complete_all\n");
}
module_init(complete_all_init);
module_exit(complete_all_exit);
